home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / gdb / foo / valprint.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-07-02  |  36.6 KB  |  1,393 lines

  1. /* Print values for GNU debugger gdb.
  2.    Copyright (C) 1986, 1988, 1989 Free Software Foundation, Inc.
  3.  
  4. This file is part of GDB.
  5.  
  6. GDB is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 1, or (at your option)
  9. any later version.
  10.  
  11. GDB is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with GDB; see the file COPYING.  If not, write to
  18. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  19.  
  20. #include <stdio.h>
  21. #include "defs.h"
  22. #include "param.h"
  23. #include "symtab.h"
  24. #include "value.h"
  25.  
  26. /* GNU software is only expected to run on systems with 32-bit integers.  */
  27. #define UINT_MAX 0xffffffff
  28.  
  29. /* Maximum number of chars to print for a string pointer value
  30.    or vector contents, or UINT_MAX for no limit.  */
  31.  
  32. static unsigned int print_max;
  33.  
  34. static void type_print_varspec_suffix ();
  35. static void type_print_varspec_prefix ();
  36. static void type_print_base ();
  37. static void type_print_method_args ();
  38.  
  39.  
  40. char **unsigned_type_table;
  41. char **signed_type_table;
  42. char **float_type_table;
  43.  
  44.  
  45. /* Print repeat counts if there are more than this
  46.    many repetitions of an element in an array.  */
  47. #define    REPEAT_COUNT_THRESHOLD    10
  48.  
  49. /* Print the character string STRING, printing at most LENGTH characters.
  50.    Printing stops early if the number hits print_max; repeat counts
  51.    are printed as appropriate.  Print ellipses at the end if we
  52.    had to stop before printing LENGTH characters, or if FORCE_ELLIPSES.  */
  53.  
  54. void
  55. print_string (stream, string, length, force_ellipses)
  56.      FILE *stream;
  57.      char *string;
  58.      unsigned int length;
  59.      int force_ellipses;
  60. {
  61.   register unsigned int i;
  62.   unsigned int things_printed = 0;
  63.   int in_quotes = 0;
  64.   int need_comma = 0;
  65.  
  66.   if (length == 0)
  67.     {
  68.       fputs_filtered ("\"\"", stdout);
  69.       return;
  70.     }
  71.  
  72.   for (i = 0; i < length && things_printed < print_max; ++i)
  73.     {
  74.       /* Position of the character we are examining
  75.      to see whether it is repeated.  */
  76.       unsigned int rep1;
  77.       /* Number of repititions we have detected so far.  */
  78.       unsigned int reps;
  79.  
  80.       QUIT;
  81.  
  82.       if (need_comma)
  83.     {
  84.       fputs_filtered (", ", stream);
  85.       need_comma = 0;
  86.     }
  87.  
  88.       rep1 = i + 1;
  89.       reps = 1;
  90.       while (rep1 < length && string[rep1] == string[i])
  91.     {
  92.       ++rep1;
  93.       ++reps;
  94.     }
  95.  
  96.       if (reps > REPEAT_COUNT_THRESHOLD)
  97.     {
  98.       if (in_quotes)
  99.         {
  100.           fputs_filtered ("\", ", stream);
  101.           in_quotes = 0;
  102.         }
  103.       fputs_filtered ("'", stream);
  104.       printchar (string[i], stream, '\'');
  105.       fprintf_filtered (stream, "' <repeats %u times>", reps);
  106.       i = rep1 - 1;
  107.       things_printed += REPEAT_COUNT_THRESHOLD;
  108.       need_comma = 1;
  109.     }
  110.       else
  111.     {
  112.       if (!in_quotes)
  113.         {
  114.           fputs_filtered ("\"", stream);
  115.           in_quotes = 1;
  116.         }
  117.       printchar (string[i], stream, '"');
  118.       ++things_printed;
  119.     }
  120.     }
  121.  
  122.   /* Terminate the quotes if necessary.  */
  123.   if (in_quotes)
  124.     fputs_filtered ("\"", stream);
  125.  
  126.   if (force_ellipses || i < length)
  127.     fputs_filtered ("...", stream);
  128. }
  129.  
  130. /* Print the value VAL in C-ish syntax on stream STREAM.
  131.    FORMAT is a format-letter, or 0 for print in natural format of data type.
  132.    If the object printed is a string pointer, returns
  133.    the number of string bytes printed.  */
  134.  
  135. int
  136. value_print (val, stream, format, pretty)
  137.      value val;
  138.      FILE *stream;
  139.      char format;
  140.      enum val_prettyprint pretty;
  141. {
  142.   register unsigned int i, n, typelen;
  143.  
  144.   /* A "repeated" value really contains several values in a row.
  145.      They are made by the @ operator.
  146.      Print such values as if they were arrays.  */
  147.  
  148.   if (VALUE_REPEATED (val))
  149.     {
  150.       n = VALUE_REPETITIONS (val);
  151.       typelen = TYPE_LENGTH (VALUE_TYPE (val));
  152.       fprintf_filtered (stream, "{");
  153.       /* Print arrays of characters using string syntax.  */
  154.       if (typelen == 1 && TYPE_CODE (VALUE_TYPE (val)) == TYPE_CODE_INT
  155.       && format == 0)
  156.     print_string (stream, VALUE_CONTENTS (val), n, 0);
  157.       else
  158.     {
  159.       unsigned int things_printed = 0;
  160.       
  161.       for (i = 0; i < n && things_printed < print_max; i++)
  162.         {
  163.           /* Position of the array element we are examining to see
  164.          whether it is repeated.  */
  165.           unsigned int rep1;
  166.           /* Number of repititions we have detected so far.  */
  167.           unsigned int reps;
  168.  
  169.           if (i != 0)
  170.         fprintf_filtered (stream, ", ");
  171.  
  172.           rep1 = i + 1;
  173.           reps = 1;
  174.           while (rep1 < n
  175.              && !bcmp (VALUE_CONTENTS (val) + typelen * i,
  176.                    VALUE_CONTENTS (val) + typelen * rep1, typelen))
  177.         {
  178.           ++reps;
  179.           ++rep1;
  180.         }
  181.  
  182.           if (reps > REPEAT_COUNT_THRESHOLD)
  183.         {
  184.           val_print (VALUE_TYPE (val),
  185.                  VALUE_CONTENTS (val) + typelen * i,
  186.                  VALUE_ADDRESS (val) + typelen * i,
  187.                  stream, format, 1, 0, pretty);
  188.           fprintf (stream, " <repeats %u times>", reps);
  189.           i = rep1 - 1;
  190.           things_printed += REPEAT_COUNT_THRESHOLD;
  191.         }
  192.           else
  193.         {
  194.           val_print (VALUE_TYPE (val),
  195.                  VALUE_CONTENTS (val) + typelen * i,
  196.                  VALUE_ADDRESS (val) + typelen * i,
  197.                  stream, format, 1, 0, pretty);
  198.           things_printed++;
  199.         }
  200.         }
  201.       if (i < n)
  202.         fprintf_filtered (stream, "...");
  203.     }
  204.       fprintf_filtered (stream, "}");
  205.       return n * typelen;
  206.     }
  207.   else
  208.     {
  209.       /* If it is a pointer, indicate what it points to.
  210.  
  211.      Print type also if it is a reference.
  212.  
  213.          C++: if it is a member pointer, we will take care
  214.      of that when we print it.  */
  215.       if (TYPE_CODE (VALUE_TYPE (val)) == TYPE_CODE_PTR
  216.       || TYPE_CODE (VALUE_TYPE (val)) == TYPE_CODE_REF)
  217.     {
  218.       fprintf_filtered (stream, "(");
  219.       type_print (VALUE_TYPE (val), "", stream, -1);
  220.       fprintf_filtered (stream, ") ");
  221.  
  222.       /* If this is a function pointer, try to print what
  223.          function it is pointing to by name.  */
  224.       if (TYPE_CODE (TYPE_TARGET_TYPE (VALUE_TYPE (val)))
  225.           == TYPE_CODE_FUNC)
  226.         {
  227.           print_address (((int *) VALUE_CONTENTS (val))[0], stream);
  228.           /* Return value is irrelevant except for string pointers.  */
  229.           return 0;
  230.         }
  231.     }
  232.       return val_print (VALUE_TYPE (val), VALUE_CONTENTS (val),
  233.             VALUE_ADDRESS (val), stream, format, 1, 0, pretty);
  234.     }
  235. }
  236.  
  237. static int prettyprint;    /* Controls prettyprinting of structures.  */
  238. int unionprint;        /* Controls printing of nested unions.  */
  239.  
  240. /* Print data of type TYPE located at VALADDR (within GDB),
  241.    which came from the inferior at address ADDRESS,
  242.    onto stdio stream STREAM according to FORMAT
  243.    (a letter or 0 for natural format).
  244.  
  245.    If the data are a string pointer, returns the number of
  246.    sting characters printed.
  247.  
  248.    if DEREF_REF is nonzero, then dereference references,
  249.    otherwise just print them like pointers.
  250.  
  251.    The PRETTY parameter controls prettyprinting.  */
  252.  
  253. int
  254. val_print (type, valaddr, address, stream, format,
  255.        deref_ref, recurse, pretty)
  256.      struct type *type;
  257.      char *valaddr;
  258.      CORE_ADDR address;
  259.      FILE *stream;
  260.      char format;
  261.      int deref_ref;
  262.      int recurse;
  263.      enum val_prettyprint pretty;
  264. {
  265.   register unsigned int i;
  266.   int len, n_baseclasses;
  267.   struct type *elttype;
  268.   int eltlen;
  269.   LONGEST val;
  270.   unsigned char c;
  271.  
  272.   if (pretty == Val_pretty_default)
  273.     {
  274.       pretty = prettyprint ? Val_prettyprint : Val_no_prettyprint;
  275.     }
  276.   
  277.   QUIT;
  278.  
  279.   if (TYPE_FLAGS (type) & TYPE_FLAG_STUB)
  280.     {
  281.       fprintf_filtered (stream, "<Type not defined in this context>");
  282.       fflush (stream);
  283.       return 0;
  284.     }
  285.   
  286.   switch (TYPE_CODE (type))
  287.     {
  288.     case TYPE_CODE_ARRAY:
  289.       if (TYPE_LENGTH (type) >= 0
  290.       && TYPE_LENGTH (TYPE_TARGET_TYPE (type)) > 0)
  291.     {
  292.       elttype = TYPE_TARGET_TYPE (type);
  293.       eltlen = TYPE_LENGTH (elttype);
  294.       len = TYPE_LENGTH (type) / eltlen;
  295.       fprintf_filtered (stream, "{");
  296.       /* For an array of chars, print with string syntax.  */
  297.       if (eltlen == 1 && TYPE_CODE (elttype) == TYPE_CODE_INT
  298.           && format == 0)
  299.         print_string (stream, valaddr, len, 0);
  300.       else
  301.         {
  302.           unsigned int things_printed = 0;
  303.           
  304.           for (i = 0; i < len && things_printed < print_max; i++)
  305.         {
  306.           /* Position of the array element we are examining to see
  307.              whether it is repeated.  */
  308.           unsigned int rep1;
  309.           /* Number of repititions we have detected so far.  */
  310.           unsigned int reps;
  311.           
  312.           if (i > 0)
  313.             fprintf_filtered (stream, ", ");
  314.           
  315.           rep1 = i + 1;
  316.           reps = 1;
  317.           while (rep1 < len
  318.              && !bcmp (valaddr + i * eltlen,
  319.                    valaddr + rep1 * eltlen, eltlen))
  320.             {
  321.               ++reps;
  322.               ++rep1;
  323.             }
  324.  
  325.           if (reps > REPEAT_COUNT_THRESHOLD)
  326.             {
  327.               val_print (elttype, valaddr + i * eltlen,
  328.                  0, stream, format, deref_ref,
  329.                  recurse + 1, pretty);
  330.               fprintf_filtered (stream, " <repeats %u times>", reps);
  331.               i = rep1 - 1;
  332.               things_printed += REPEAT_COUNT_THRESHOLD;
  333.             }
  334.           else
  335.             {
  336.               val_print (elttype, valaddr + i * eltlen,
  337.                  0, stream, format, deref_ref,
  338.                  recurse + 1, pretty);
  339.               things_printed++;
  340.             }
  341.         }
  342.           if (i < len)
  343.         fprintf_filtered (stream, "...");
  344.         }
  345.       fprintf_filtered (stream, "}");
  346.       break;
  347.     }
  348.       /* Array of unspecified length: treat like pointer to first elt.  */
  349.       valaddr = (char *) &address;
  350.  
  351.     case TYPE_CODE_PTR:
  352.       if (format)
  353.     {
  354.       print_scalar_formatted (valaddr, type, format, 0, stream);
  355.       break;
  356.     }
  357.       if (TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_METHOD)
  358.     {
  359.       struct type *domain = TYPE_DOMAIN_TYPE (TYPE_TARGET_TYPE (type));
  360.       struct type *target = TYPE_TARGET_TYPE (TYPE_TARGET_TYPE (type));
  361.       struct fn_field *f;
  362.       int j, len2;
  363.       char *kind = "";
  364.  
  365.       val = unpack_long (builtin_type_int, valaddr);
  366.       if (val < 128)
  367.         {
  368.           len = TYPE_NFN_FIELDS (domain);
  369.           for (i = 0; i < len; i++)
  370.         {
  371.           f = TYPE_FN_FIELDLIST1 (domain, i);
  372.           len2 = TYPE_FN_FIELDLIST_LENGTH (domain, i);
  373.  
  374.           for (j = 0; j < len2; j++)
  375.             {
  376.               QUIT;
  377.               if (TYPE_FN_FIELD_VOFFSET (f, j) == val)
  378.             {
  379.               kind = "virtual";
  380.               goto common;
  381.             }
  382.             }
  383.         }
  384.         }
  385.       else
  386.         {
  387.           struct symbol *sym = find_pc_function ((CORE_ADDR) val);
  388.           if (sym == 0)
  389.         error ("invalid pointer to member function");
  390.           len = TYPE_NFN_FIELDS (domain);
  391.           for (i = 0; i < len; i++)
  392.         {
  393.           f = TYPE_FN_FIELDLIST1 (domain, i);
  394.           len2 = TYPE_FN_FIELDLIST_LENGTH (domain, i);
  395.  
  396.           for (j = 0; j < len2; j++)
  397.             {
  398.               QUIT;
  399.               if (!strcmp (SYMBOL_NAME (sym), TYPE_FN_FIELD_PHYSNAME (f, j)))
  400.             goto common;
  401.             }
  402.         }
  403.         }
  404.     common:
  405.       if (i < len)
  406.         {
  407.           fprintf_filtered (stream, "&");
  408.           type_print_varspec_prefix (TYPE_FN_FIELD_TYPE (f, j), stream, 0, 0);
  409.           fprintf (stream, kind);
  410.           if (TYPE_FN_FIELD_PHYSNAME (f, j)[0] == '_'
  411.           && TYPE_FN_FIELD_PHYSNAME (f, j)[1] == '$')
  412.         type_print_method_args
  413.           (TYPE_FN_FIELD_ARGS (f, j) + 1, "~",
  414.            TYPE_FN_FIELDLIST_NAME (domain, i), 0, stream);
  415.           else
  416.         type_print_method_args
  417.           (TYPE_FN_FIELD_ARGS (f, j), "",
  418.            TYPE_FN_FIELDLIST_NAME (domain, i), 0, stream);
  419.           break;
  420.         }
  421.       fprintf_filtered (stream, "(");
  422.         type_print (type, "", stream, -1);
  423.       fprintf_filtered (stream, ") %d", (int) val >> 3);
  424.     }
  425.       else if (TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_MEMBER)
  426.     {
  427.       struct type *domain = TYPE_DOMAIN_TYPE (TYPE_TARGET_TYPE (type));
  428.       struct type *target = TYPE_TARGET_TYPE (TYPE_TARGET_TYPE (type));
  429.       char *kind = "";
  430.  
  431.       /* VAL is a byte offset into the structure type DOMAIN.
  432.          Find the name of the field for that offset and
  433.          print it.  */
  434.       int extra = 0;
  435.       int bits = 0;
  436.       len = TYPE_NFIELDS (domain);
  437.       /* @@ Make VAL into bit offset */
  438.       val = unpack_long (builtin_type_int, valaddr) << 3;
  439.       for (i = 0; i < len; i++)
  440.         {
  441.           int bitpos = TYPE_FIELD_BITPOS (domain, i);
  442.           QUIT;
  443.           if (val == bitpos)
  444.         break;
  445.           if (val < bitpos && i > 0)
  446.         {
  447.           int ptrsize = (TYPE_LENGTH (builtin_type_char) * TYPE_LENGTH (target));
  448.           /* Somehow pointing into a field.  */
  449.           i -= 1;
  450.           extra = (val - TYPE_FIELD_BITPOS (domain, i));
  451.           if (extra & 0x3)
  452.             bits = 1;
  453.           else
  454.             extra >>= 3;
  455.           break;
  456.         }
  457.         }
  458.       if (i < len)
  459.         {
  460.           fprintf_filtered (stream, "&");
  461.           type_print_base (domain, stream, 0, 0);
  462.           fprintf_filtered (stream, "::");
  463.           fputs_filtered (TYPE_FIELD_NAME (domain, i), stream);
  464.           if (extra)
  465.         fprintf_filtered (stream, " + %d bytes", extra);
  466.           if (bits)
  467.         fprintf_filtered (stream, " (offset in bits)");
  468.           break;
  469.         }
  470.       fprintf_filtered (stream, "%d", val >> 3);
  471.     }
  472.       else
  473.     {
  474.       fprintf_filtered (stream, "0x%x", * (int *) valaddr);
  475.       /* For a pointer to char or unsigned char,
  476.          also print the string pointed to, unless pointer is null.  */
  477.       
  478.       /* For an array of chars, print with string syntax.  */
  479.       elttype = TYPE_TARGET_TYPE (type);
  480.       i = 0;        /* Number of characters printed.  */
  481.       if (TYPE_LENGTH (elttype) == 1 
  482.           && TYPE_CODE (elttype) == TYPE_CODE_INT
  483.           && format == 0
  484.           && unpack_long (type, valaddr) != 0
  485.           /* If print_max is UINT_MAX, the alloca below will fail.
  486.              In that case don't try to print the string.  */
  487.           && print_max < UINT_MAX)
  488.         {
  489.           fprintf_filtered (stream, " ");
  490.  
  491.           /* Get first character.  */
  492.           if (read_memory ( (CORE_ADDR) unpack_long (type, valaddr),
  493.                    &c, 1))
  494.         {
  495.           /* First address out of bounds.  */
  496.           fprintf_filtered (stream, "<Address 0x%x out of bounds>",
  497.                (* (int *) valaddr));
  498.           break;
  499.         }
  500.           else
  501.         {
  502.           /* A real string.  */
  503.           int out_of_bounds = 0;
  504.           char *string = (char *) alloca (print_max);
  505.  
  506.           /* If the loop ends by us hitting print_max characters,
  507.              we need to have elipses at the end.  */
  508.           int force_ellipses = 1;
  509.  
  510.           /* This loop only fetches print_max characters, even
  511.              though print_string might want to print more
  512.              (with repeated characters).  This is so that
  513.              we don't spend forever fetching if we print
  514.              a long string consisting of the same character
  515.              repeated.  */
  516.           while (i < print_max)
  517.             {
  518.               QUIT;
  519.               if (read_memory ((CORE_ADDR) unpack_long (type, valaddr)
  520.                        + i, &c, 1))
  521.             {
  522.               out_of_bounds = 1;
  523.               force_ellipses = 0;
  524.               break;
  525.             }
  526.               else if (c == '\0')
  527.             {
  528.               force_ellipses = 0;
  529.               break;
  530.             }
  531.               else
  532.             string[i++] = c;
  533.             }
  534.  
  535.           print_string (stream, string, i, force_ellipses);
  536.           if (out_of_bounds)
  537.             fprintf_filtered (stream,
  538.                       " <Address 0x%x out of bounds>",
  539.                       (*(int *) valaddr) + i);
  540.         }
  541.  
  542.           fflush (stream);
  543.         }
  544.       /* Return number of characters printed, plus one for the
  545.          terminating null if we have "reached the end".  */
  546.       return i + (print_max && i != print_max);
  547.     }
  548.       break;
  549.  
  550.     case TYPE_CODE_MEMBER:
  551.       error ("not implemented: member type in val_print");
  552.       break;
  553.  
  554.     case TYPE_CODE_REF:
  555.       fprintf_filtered (stream, "(0x%x &) = ", * (int *) valaddr);
  556.       /* De-reference the reference.  */
  557.       if (deref_ref)
  558.     {
  559.       if (TYPE_CODE (TYPE_TARGET_TYPE (type)) != TYPE_CODE_UNDEF)
  560.         {
  561.           value val = value_at (TYPE_TARGET_TYPE (type), * (int *) valaddr);
  562.           val_print (VALUE_TYPE (val), VALUE_CONTENTS (val),
  563.              VALUE_ADDRESS (val), stream, format,
  564.              deref_ref, recurse + 1, pretty);
  565.         }
  566.       else
  567.         fprintf_filtered (stream, "???");
  568.     }
  569.       break;
  570.  
  571.     case TYPE_CODE_UNION:
  572.       if (recurse && !unionprint)
  573.     {
  574.       fprintf_filtered (stream, "{...}");
  575.       break;
  576.     }
  577.       /* Fall through.  */
  578.     case TYPE_CODE_STRUCT:
  579.       fprintf_filtered (stream, "{");
  580.       len = TYPE_NFIELDS (type);
  581.       n_baseclasses = TYPE_N_BASECLASSES (type);
  582.       for (i = 1; i <= n_baseclasses; i++)
  583.     {
  584.       fprintf_filtered (stream, "\n");
  585.       if (pretty)
  586.         print_spaces_filtered (2 + 2 * recurse, stream);
  587.       fputs_filtered ("<", stream);
  588.       fputs_filtered (TYPE_NAME (TYPE_BASECLASS (type, i)), stream);
  589.       fputs_filtered ("> = ", stream);
  590.       val_print (TYPE_FIELD_TYPE (type, 0),
  591.              valaddr + TYPE_FIELD_BITPOS (type, i-1) / 8,
  592.              0, stream, 0, 0, recurse + 1, pretty);
  593.     }
  594.       if (i > 1) {
  595.     fprintf_filtered (stream, "\n");
  596.     print_spaces_filtered (2 + 2 * recurse, stream);
  597.     fputs_filtered ("members of ", stream);
  598.         fputs_filtered (TYPE_NAME (type), stream);
  599.         fputs_filtered (": ", stream);
  600.       }
  601.       if (!len && i == 1)
  602.     fprintf_filtered (stream, "<No data fields>");
  603.       else
  604.     {
  605.       for (i -= 1; i < len; i++)
  606.         {
  607.           if (i > n_baseclasses) fprintf_filtered (stream, ", ");
  608.           if (pretty)
  609.         {
  610.           fprintf_filtered (stream, "\n");
  611.           print_spaces_filtered (2 + 2 * recurse, stream);
  612.         }
  613.           fputs_filtered (TYPE_FIELD_NAME (type, i), stream);
  614.           fputs_filtered (" = ", stream);
  615.           /* check if static field */
  616.           if (TYPE_FIELD_STATIC (type, i))
  617.         {
  618.           value v;
  619.           
  620.           v = value_static_field (type, TYPE_FIELD_NAME (type, i), i);
  621.           val_print (TYPE_FIELD_TYPE (type, i),
  622.                  VALUE_CONTENTS (v), 0, stream, format,
  623.                  deref_ref, recurse + 1, pretty);
  624.         }
  625.           else if (TYPE_FIELD_PACKED (type, i))
  626.         {
  627.           char *valp = (char *) & val;
  628.           union {int i; char c;} test;
  629.           test.i = 1;
  630.           if (test.c != 1)
  631.             valp += sizeof val - TYPE_LENGTH (TYPE_FIELD_TYPE (type, i));
  632.           val = unpack_field_as_long (type, valaddr, i);
  633.           val_print (TYPE_FIELD_TYPE (type, i), valp, 0,
  634.                  stream, format, deref_ref, recurse + 1, pretty);
  635.         }
  636.           else
  637.         {
  638.           val_print (TYPE_FIELD_TYPE (type, i), 
  639.                  valaddr + TYPE_FIELD_BITPOS (type, i) / 8,
  640.                  0, stream, format, deref_ref,
  641.                  recurse + 1, pretty);
  642.         }
  643.         }
  644.       if (pretty)
  645.         {
  646.           fprintf_filtered (stream, "\n");
  647.           print_spaces_filtered (2 * recurse, stream);
  648.         }
  649.     }
  650.       fprintf_filtered (stream, "}");
  651.       break;
  652.  
  653.     case TYPE_CODE_ENUM:
  654.       if (format)
  655.     {
  656.       print_scalar_formatted (valaddr, type, format, 0, stream);
  657.       break;
  658.     }
  659.       len = TYPE_NFIELDS (type);
  660.       val = unpack_long (builtin_type_int, valaddr);
  661.       for (i = 0; i < len; i++)
  662.     {
  663.       QUIT;
  664.       if (val == TYPE_FIELD_BITPOS (type, i))
  665.         break;
  666.     }
  667.       if (i < len)
  668.     fputs_filtered (TYPE_FIELD_NAME (type, i), stream);
  669.       else
  670.     fprintf_filtered (stream, "%d", (int) val);
  671.       break;
  672.  
  673.     case TYPE_CODE_FUNC:
  674.       if (format)
  675.     {
  676.       print_scalar_formatted (valaddr, type, format, 0, stream);
  677.       break;
  678.     }
  679.       fprintf_filtered (stream, "{");
  680.       type_print (type, "", stream, -1);
  681.       fprintf_filtered (stream, "} ");
  682.       fprintf_filtered (stream, "0x%x", address);
  683.       break;
  684.  
  685.     case TYPE_CODE_INT:
  686.       if (format)
  687.     {
  688.       print_scalar_formatted (valaddr, type, format, 0, stream);
  689.       break;
  690.     }
  691. #ifdef PRINT_TYPELESS_INTEGER
  692.       PRINT_TYPELESS_INTEGER (stream, type, unpack_long (type, valaddr));
  693. #else
  694. #ifndef LONG_LONG
  695.       fprintf_filtered (stream,
  696.             TYPE_UNSIGNED (type) ? "%u" : "%d",
  697.             unpack_long (type, valaddr));
  698. #else
  699.       fprintf_filtered (stream,
  700.             TYPE_UNSIGNED (type) ? "%llu" : "%lld",
  701.             unpack_long (type, valaddr));
  702. #endif
  703. #endif
  704.             
  705.       if (TYPE_LENGTH (type) == 1)
  706.     {
  707.       fprintf_filtered (stream, " '");
  708.       printchar ((unsigned char) unpack_long (type, valaddr), 
  709.              stream, '\'');
  710.       fprintf_filtered (stream, "'");
  711.     }
  712.       break;
  713.  
  714.     case TYPE_CODE_FLT:
  715.       if (format)
  716.     {
  717.       print_scalar_formatted (valaddr, type, format, 0, stream);
  718.       break;
  719.     }
  720. #ifdef IEEE_FLOAT
  721.       if (is_nan ((char *) valaddr, TYPE_LENGTH (type)))
  722.     {
  723.       fprintf_filtered (stream, "NaN");
  724.       break;
  725.     }
  726. #endif
  727.       {
  728.     double doub;
  729.     int inv;
  730.  
  731.     doub = unpack_double (type, valaddr, &inv);
  732.     if (inv)
  733.       fprintf_filtered (stream, "Invalid float value");
  734.     else
  735.       fprintf_filtered (stream,
  736.                 TYPE_LENGTH (type) <= 4? "%.6g": "%.16g", doub);
  737.       }
  738.       break;
  739.  
  740.     case TYPE_CODE_VOID:
  741.       fprintf_filtered (stream, "void");
  742.       break;
  743.  
  744.     default:
  745.       error ("Invalid type code in symbol table.");
  746.     }
  747.   fflush (stream);
  748.   return 0;
  749. }
  750.  
  751. #ifdef IEEE_FLOAT
  752.  
  753. /* Nonzero if ARG (a double) is a NAN.  */
  754.  
  755. int
  756. is_nan (fp, len)
  757.      char *fp;
  758.      int len;
  759. {
  760.   int lowhalf, highhalf;
  761.   union ieee
  762.     {
  763.       long i[2];        /* ASSUMED 32 BITS */
  764.       float f;        /* ASSUMED 32 BITS */
  765.       double d;        /* ASSUMED 64 BITS */
  766.     } *arg;
  767.  
  768.   arg = (union ieee *)fp;
  769.  
  770.   /*
  771.    * Single precision float.
  772.    */
  773.   if (len == sizeof(long))
  774.     {
  775.       highhalf = arg->i[0];
  776.       return ((((highhalf >> 23) & 0xFF) == 0xFF) 
  777.           && 0 != (highhalf & 0x7FFFFF));
  778.     }
  779.   
  780.   /* Separate the high and low words of the double.
  781.      Distinguish big and little-endian machines.  */
  782. #ifdef WORDS_BIG_ENDIAN
  783.     lowhalf = arg->i[1], highhalf = arg->i[0];
  784. #else
  785.     lowhalf = arg->i[0], highhalf = arg->i[1];
  786. #endif
  787.   
  788.   /* Nan: exponent is the maximum possible, and fraction is nonzero.  */
  789.   return (((highhalf>>20) & 0x7ff) == 0x7ff
  790.       && ! ((highhalf & 0xfffff == 0) && (lowhalf == 0)));
  791. }
  792. #endif
  793.  
  794. /* Print a description of a type TYPE
  795.    in the form of a declaration of a variable named VARSTRING.
  796.    Output goes to STREAM (via stdio).
  797.    If SHOW is positive, we show the contents of the outermost level
  798.    of structure even if there is a type name that could be used instead.
  799.    If SHOW is negative, we never show the details of elements' types.  */
  800.  
  801. void
  802. type_print (type, varstring, stream, show)
  803.      struct type *type;
  804.      char *varstring;
  805.      FILE *stream;
  806.      int show;
  807. {
  808.   type_print_1 (type, varstring, stream, show, 0);
  809. }
  810.  
  811. /* LEVEL is the depth to indent lines by.  */
  812.  
  813. void
  814. type_print_1 (type, varstring, stream, show, level)
  815.      struct type *type;
  816.      char *varstring;
  817.      FILE *stream;
  818.      int show;
  819.      int level;
  820. {
  821.   register enum type_code code;
  822.   type_print_base (type, stream, show, level);
  823.   code = TYPE_CODE (type);
  824.   if ((varstring && *varstring)
  825.       ||
  826.       /* Need a space if going to print stars or brackets;
  827.      but not if we will print just a type name.  */
  828.       ((show > 0 || TYPE_NAME (type) == 0)
  829.        &&
  830.        (code == TYPE_CODE_PTR || code == TYPE_CODE_FUNC
  831.     || code == TYPE_CODE_METHOD
  832.     || code == TYPE_CODE_ARRAY
  833.     || code == TYPE_CODE_MEMBER
  834.     || code == TYPE_CODE_REF)))
  835.     fprintf_filtered (stream, " ");
  836.   type_print_varspec_prefix (type, stream, show, 0);
  837.   fputs_filtered (varstring, stream);
  838.   type_print_varspec_suffix (type, stream, show, 0);
  839. }
  840.  
  841. /* Print the method arguments ARGS to the file STREAM.  */
  842. static void
  843. type_print_method_args (args, prefix, varstring, staticp, stream)
  844.      struct type **args;
  845.      char *prefix, *varstring;
  846.      int staticp;
  847.      FILE *stream;
  848. {
  849.   int i;
  850.  
  851.   fputs_filtered (" ", stream);
  852.   fputs_filtered (prefix, stream);
  853.   fputs_filtered (varstring, stream);
  854.   fputs_filtered (" (", stream);
  855.   if (args && args[!staticp] && args[!staticp]->code != TYPE_CODE_VOID)
  856.     {
  857.       i = !staticp;        /* skip the class variable */
  858.       while (1)
  859.     {
  860.       type_print (args[i++], "", stream, 0);
  861.       if (!args[i]) 
  862.         {
  863.           fprintf_filtered (stream, " ...");
  864.           break;
  865.         }
  866.       else if (args[i]->code != TYPE_CODE_VOID)
  867.         {
  868.           fprintf_filtered (stream, ", ");
  869.         }
  870.       else break;
  871.     }
  872.     }
  873.   fprintf_filtered (stream, ")");
  874. }
  875.   
  876. /* If TYPE is a derived type, then print out derivation
  877.    information.  Print out all layers of the type heirarchy
  878.    until we encounter one with multiple inheritance.
  879.    At that point, print out that ply, and return.  */
  880. static void
  881. type_print_derivation_info (stream, type)
  882.      FILE *stream;
  883.      struct type *type;
  884. {
  885.   char *name;
  886.   int i, n_baseclasses = TYPE_N_BASECLASSES (type);
  887.   struct type *basetype = 0;
  888.  
  889.   while (type && n_baseclasses == 1)
  890.     {
  891.       basetype = TYPE_BASECLASS (type, 1);
  892.       if (TYPE_NAME (basetype) && (name = TYPE_NAME (basetype)))
  893.     {
  894.       while (*name != ' ') name++;
  895.       fprintf_filtered (stream, ": %s%s ",
  896.            TYPE_VIA_PUBLIC (basetype) ? "public" : "private",
  897.            TYPE_VIA_VIRTUAL (basetype) ? " virtual" : "");
  898.       fputs_filtered (name + 1, stream);
  899.       fputs_filtered (" ", stream);
  900.     }
  901.       n_baseclasses = TYPE_N_BASECLASSES (basetype);
  902.       type = basetype;
  903.     }
  904.  
  905.   if (type)
  906.     {
  907.       if (n_baseclasses != 0)
  908.     fprintf_filtered (stream, ": ");
  909.       for (i = 1; i <= n_baseclasses; i++)
  910.     {
  911.       basetype = TYPE_BASECLASS (type, i);
  912.       if (TYPE_NAME (basetype) && (name = TYPE_NAME (basetype)))
  913.         {
  914.           while (*name != ' ') name++;
  915.           fprintf_filtered (stream, "%s%s ",
  916.                TYPE_VIA_PUBLIC (basetype) ? "public" : "private",
  917.                TYPE_VIA_VIRTUAL (basetype) ? " virtual" : "");
  918.           fputs_filtered (name + 1, stream);
  919.         }
  920.       if (i < n_baseclasses)
  921.         fprintf_filtered (stream, ", ");
  922.     }
  923.       fprintf_filtered (stream, " ");
  924.     }
  925. }
  926.  
  927. /* Print any asterisks or open-parentheses needed before the
  928.    variable name (to describe its type).
  929.  
  930.    On outermost call, pass 0 for PASSED_A_PTR.
  931.    On outermost call, SHOW > 0 means should ignore
  932.    any typename for TYPE and show its details.
  933.    SHOW is always zero on recursive calls.  */
  934.  
  935. static void
  936. type_print_varspec_prefix (type, stream, show, passed_a_ptr)
  937.      struct type *type;
  938.      FILE *stream;
  939.      int show;
  940.      int passed_a_ptr;
  941. {
  942.   if (type == 0)
  943.     return;
  944.  
  945.   if (TYPE_NAME (type) && show <= 0)
  946.     return;
  947.  
  948.   QUIT;
  949.  
  950.   switch (TYPE_CODE (type))
  951.     {
  952.     case TYPE_CODE_PTR:
  953.       type_print_varspec_prefix (TYPE_TARGET_TYPE (type), stream, 0, 1);
  954.       fprintf_filtered (stream, "*");
  955.       break;
  956.  
  957.     case TYPE_CODE_MEMBER:
  958.       if (passed_a_ptr)
  959.     fprintf_filtered (stream, "(");
  960.       type_print_varspec_prefix (TYPE_TARGET_TYPE (type), stream, 0,
  961.                  0);
  962.       fprintf_filtered (stream, " ");
  963.       type_print_base (TYPE_DOMAIN_TYPE (type), stream, 0,
  964.                passed_a_ptr);
  965.       fprintf_filtered (stream, "::");
  966.       break;
  967.  
  968.     case TYPE_CODE_METHOD:
  969.       if (passed_a_ptr)
  970.     fprintf (stream, "(");
  971.       type_print_varspec_prefix (TYPE_TARGET_TYPE (type), stream, 0,
  972.                  0);
  973.       fprintf_filtered (stream, " ");
  974.       type_print_base (TYPE_DOMAIN_TYPE (type), stream, 0,
  975.                passed_a_ptr);
  976.       fprintf_filtered (stream, "::");
  977.       break;
  978.  
  979.     case TYPE_CODE_REF:
  980.       type_print_varspec_prefix (TYPE_TARGET_TYPE (type), stream, 0, 1);
  981.       fprintf_filtered (stream, "&");
  982.       break;
  983.  
  984.     case TYPE_CODE_FUNC:
  985.       type_print_varspec_prefix (TYPE_TARGET_TYPE (type), stream, 0,
  986.                  0);
  987.       if (passed_a_ptr)
  988.     fprintf_filtered (stream, "(");
  989.       break;
  990.  
  991.     case TYPE_CODE_ARRAY:
  992.       type_print_varspec_prefix (TYPE_TARGET_TYPE (type), stream, 0,
  993.                  0);
  994.       if (passed_a_ptr)
  995.     fprintf_filtered (stream, "(");
  996.     }
  997. }
  998.  
  999. /* Print any array sizes, function arguments or close parentheses
  1000.    needed after the variable name (to describe its type).
  1001.    Args work like type_print_varspec_prefix.  */
  1002.  
  1003. static void
  1004. type_print_varspec_suffix (type, stream, show, passed_a_ptr)
  1005.      struct type *type;
  1006.      FILE *stream;
  1007.      int show;
  1008.      int passed_a_ptr;
  1009. {
  1010.   if (type == 0)
  1011.     return;
  1012.  
  1013.   if (TYPE_NAME (type) && show <= 0)
  1014.     return;
  1015.  
  1016.   QUIT;
  1017.  
  1018.   switch (TYPE_CODE (type))
  1019.     {
  1020.     case TYPE_CODE_ARRAY:
  1021.       if (passed_a_ptr)
  1022.     fprintf_filtered (stream, ")");
  1023.       
  1024.       fprintf_filtered (stream, "[");
  1025.       if (TYPE_LENGTH (type) >= 0
  1026.       && TYPE_LENGTH (TYPE_TARGET_TYPE (type)) > 0)
  1027.     fprintf_filtered (stream, "%d",
  1028.               (TYPE_LENGTH (type)
  1029.                / TYPE_LENGTH (TYPE_TARGET_TYPE (type))));
  1030.       fprintf_filtered (stream, "]");
  1031.       
  1032.       type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, 0,
  1033.                  0);
  1034.       break;
  1035.  
  1036.     case TYPE_CODE_MEMBER:
  1037.       if (passed_a_ptr)
  1038.     fprintf_filtered (stream, ")");
  1039.       type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, 0, 0);
  1040.       break;
  1041.  
  1042.     case TYPE_CODE_METHOD:
  1043.       if (passed_a_ptr)
  1044.     fprintf_filtered (stream, ")");
  1045.       type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, 0, 0);
  1046.       if (passed_a_ptr)
  1047.     {
  1048.       int i;
  1049.       struct type **args = TYPE_ARG_TYPES (type);
  1050.  
  1051.       fprintf_filtered (stream, "(");
  1052.       if (args[1] == 0)
  1053.         fprintf_filtered (stream, "...");
  1054.       else for (i = 1; args[i] != 0 && args[i]->code != TYPE_CODE_VOID; i++)
  1055.         {
  1056.           type_print_1 (args[i], "", stream, -1, 0);
  1057.           if (args[i+1] == 0)
  1058.         fprintf_filtered (stream, "...");
  1059.           else if (args[i+1]->code != TYPE_CODE_VOID)
  1060.         fprintf_filtered (stream, ",");
  1061.         }
  1062.       fprintf_filtered (stream, ")");
  1063.     }
  1064.       break;
  1065.  
  1066.     case TYPE_CODE_PTR:
  1067.     case TYPE_CODE_REF:
  1068.       type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, 0, 1);
  1069.       break;
  1070.  
  1071.     case TYPE_CODE_FUNC:
  1072.       type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, 0,
  1073.                  passed_a_ptr);
  1074.       if (passed_a_ptr)
  1075.     fprintf_filtered (stream, ")");
  1076.       fprintf_filtered (stream, "()");
  1077.       break;
  1078.     }
  1079. }
  1080.  
  1081. /* Print the name of the type (or the ultimate pointer target,
  1082.    function value or array element), or the description of a
  1083.    structure or union.
  1084.  
  1085.    SHOW nonzero means don't print this type as just its name;
  1086.    show its real definition even if it has a name.
  1087.    SHOW zero means print just typename or struct tag if there is one
  1088.    SHOW negative means abbreviate structure elements.
  1089.    SHOW is decremented for printing of structure elements.
  1090.  
  1091.    LEVEL is the depth to indent by.
  1092.    We increase it for some recursive calls.  */
  1093.  
  1094. static void
  1095. type_print_base (type, stream, show, level)
  1096.      struct type *type;
  1097.      FILE *stream;
  1098.      int show;
  1099.      int level;
  1100. {
  1101.   char *name;
  1102.   register int i;
  1103.   register int len;
  1104.   register int lastval;
  1105.  
  1106.   QUIT;
  1107.  
  1108.   if (type == 0)
  1109.     {
  1110.       fprintf_filtered (stream, "type unknown");
  1111.       return;
  1112.     }
  1113.  
  1114.   if (TYPE_NAME (type) && show <= 0)
  1115.     {
  1116.       fputs_filtered (TYPE_NAME (type), stream);
  1117.       return;
  1118.     }
  1119.  
  1120.   switch (TYPE_CODE (type))
  1121.     {
  1122.     case TYPE_CODE_ARRAY:
  1123.     case TYPE_CODE_PTR:
  1124.     case TYPE_CODE_MEMBER:
  1125.     case TYPE_CODE_REF:
  1126.     case TYPE_CODE_FUNC:
  1127.     case TYPE_CODE_METHOD:
  1128.       type_print_base (TYPE_TARGET_TYPE (type), stream, show, level);
  1129.       break;
  1130.  
  1131.     case TYPE_CODE_STRUCT:
  1132.       fprintf_filtered (stream, "struct ");
  1133.       goto struct_union;
  1134.  
  1135.     case TYPE_CODE_UNION:
  1136.       fprintf_filtered (stream, "union ");
  1137.     struct_union:
  1138.       if (TYPE_NAME (type) && (name = TYPE_NAME (type)))
  1139.     {
  1140.       while (*name != ' ') name++;
  1141.       fputs_filtered (name + 1, stream);
  1142.       fputs_filtered (" ", stream);
  1143.     }
  1144.       if (show < 0)
  1145.     fprintf_filtered (stream, "{...}");
  1146.       else
  1147.     {
  1148.       int i;
  1149.  
  1150.       type_print_derivation_info (stream, type);
  1151.       
  1152.       fprintf_filtered (stream, "{");
  1153.       len = TYPE_NFIELDS (type);
  1154.       if (len)
  1155.         fprintf_filtered (stream, "\n");
  1156.       else
  1157.         {
  1158.           if (TYPE_FLAGS (type) & TYPE_FLAG_STUB)
  1159.         fprintf_filtered (stream, "<incomplete type>\n");
  1160.           else
  1161.         fprintf_filtered (stream, "<no data fields>\n");
  1162.         }
  1163.  
  1164.       /* If there is a base class for this type,
  1165.          do not print the field that it occupies.  */
  1166.       for (i = TYPE_N_BASECLASSES (type); i < len; i++)
  1167.         {
  1168.           QUIT;
  1169.           /* Don't print out virtual function table.  */
  1170.           if (! strncmp (TYPE_FIELD_NAME (type, i),
  1171.                "_vptr$", 6))
  1172.         continue;
  1173.  
  1174.           print_spaces_filtered (level + 4, stream);
  1175.           if (TYPE_FIELD_STATIC (type, i))
  1176.         {
  1177.           fprintf_filtered (stream, "static ");
  1178.         }
  1179.           type_print_1 (TYPE_FIELD_TYPE (type, i),
  1180.                 TYPE_FIELD_NAME (type, i),
  1181.                 stream, show - 1, level + 4);
  1182.           if (!TYPE_FIELD_STATIC (type, i)
  1183.           && TYPE_FIELD_PACKED (type, i))
  1184.         {
  1185.           /* It is a bitfield.  This code does not attempt
  1186.              to look at the bitpos and reconstruct filler,
  1187.              unnamed fields.  This would lead to misleading
  1188.              results if the compiler does not put out fields
  1189.              for such things (I don't know what it does).  */
  1190.           fprintf_filtered (stream, " : %d",
  1191.                     TYPE_FIELD_BITSIZE (type, i));
  1192.         }
  1193.           fprintf_filtered (stream, ";\n");
  1194.         }
  1195.  
  1196.       /* C++: print out the methods */
  1197.       len = TYPE_NFN_FIELDS (type);
  1198.       if (len) fprintf_filtered (stream, "\n");
  1199.       for (i = 0; i < len; i++)
  1200.         {
  1201.           struct fn_field *f = TYPE_FN_FIELDLIST1 (type, i);
  1202.           int j, len2 = TYPE_FN_FIELDLIST_LENGTH (type, i);
  1203.  
  1204.           for (j = 0; j < len2; j++)
  1205.         {
  1206.           QUIT;
  1207.           print_spaces_filtered (level + 4, stream);
  1208.           if (TYPE_FN_FIELD_VIRTUAL_P (f, j))
  1209.             fprintf_filtered (stream, "virtual ");
  1210.           else if (TYPE_FN_FIELD_STATIC_P (f, j))
  1211.             fprintf_filtered (stream, "static ");
  1212.           type_print (TYPE_TARGET_TYPE (TYPE_FN_FIELD_TYPE (f, j)), "", stream, 0);
  1213.           if (TYPE_FN_FIELD_PHYSNAME (f, j)[0] == '_'
  1214.               && TYPE_FN_FIELD_PHYSNAME (f, j)[1] == '$')
  1215.             type_print_method_args
  1216.               (TYPE_FN_FIELD_ARGS (f, j) + 1, "~",
  1217.                TYPE_FN_FIELDLIST_NAME (type, i), 0, stream);
  1218.           else
  1219.             type_print_method_args
  1220.               (TYPE_FN_FIELD_ARGS (f, j), "",
  1221.                TYPE_FN_FIELDLIST_NAME (type, i),
  1222.                TYPE_FN_FIELD_STATIC_P (f, j), stream);
  1223.  
  1224.           fprintf_filtered (stream, ";\n");
  1225.         }
  1226.           if (len2) fprintf_filtered (stream, "\n");
  1227.         }
  1228.  
  1229.       print_spaces_filtered (level, stream);
  1230.       fprintf_filtered (stream, "}");
  1231.     }
  1232.       break;
  1233.  
  1234.     case TYPE_CODE_ENUM:
  1235.       fprintf_filtered (stream, "enum ");
  1236.       if (TYPE_NAME (type))
  1237.     {
  1238.       name = TYPE_NAME (type);
  1239.       while (*name != ' ') name++;
  1240.       fputs_filtered (name + 1, stream);
  1241.       fputs_filtered (" ", stream);
  1242.     }
  1243.       if (show < 0)
  1244.     fprintf_filtered (stream, "{...}");
  1245.       else
  1246.     {
  1247.       fprintf_filtered (stream, "{");
  1248.       len = TYPE_NFIELDS (type);
  1249.       lastval = 0;
  1250.       for (i = 0; i < len; i++)
  1251.         {
  1252.           QUIT;
  1253.           if (i) fprintf_filtered (stream, ", ");
  1254.           fputs_filtered (TYPE_FIELD_NAME (type, i), stream);
  1255.           if (lastval != TYPE_FIELD_BITPOS (type, i))
  1256.         {
  1257.           fprintf_filtered (stream, " : %d", TYPE_FIELD_BITPOS (type, i));
  1258.           lastval = TYPE_FIELD_BITPOS (type, i);
  1259.         }
  1260.           lastval++;
  1261.         }
  1262.       fprintf_filtered (stream, "}");
  1263.     }
  1264.       break;
  1265.  
  1266.     case TYPE_CODE_INT:
  1267.       if (TYPE_UNSIGNED (type))
  1268.     name = unsigned_type_table[TYPE_LENGTH (type)];
  1269.       else
  1270.     name = signed_type_table[TYPE_LENGTH (type)];
  1271.       fputs_filtered (name, stream);
  1272.       break;
  1273.  
  1274.     case TYPE_CODE_FLT:
  1275.       name = float_type_table[TYPE_LENGTH (type)];
  1276.       fputs_filtered (name, stream);
  1277.       break;
  1278.  
  1279.     case TYPE_CODE_VOID:
  1280.       fprintf_filtered (stream, "void");
  1281.       break;
  1282.  
  1283.     case 0:
  1284.       fprintf_filtered (stream, "struct unknown");
  1285.       break;
  1286.  
  1287.     default:
  1288.       error ("Invalid type code in symbol table.");
  1289.     }
  1290. }
  1291.  
  1292. static void
  1293. set_maximum_command (arg)
  1294.      char *arg;
  1295. {
  1296.   if (!arg) error_no_arg ("value for maximum elements to print");
  1297.   print_max = parse_and_eval_address (arg);
  1298.   if (print_max == 0)
  1299.     print_max = UINT_MAX;
  1300. }
  1301.  
  1302. static void
  1303. set_prettyprint_command (arg, from_tty)
  1304.      char *arg;
  1305.      int from_tty;
  1306. {
  1307.   prettyprint = parse_binary_operation ("set prettyprint", arg);
  1308. }
  1309.  
  1310. static void
  1311. set_unionprint_command (arg, from_tty)
  1312.      char *arg;
  1313.      int from_tty;
  1314. {
  1315.   unionprint = parse_binary_operation ("set unionprint", arg);
  1316. }
  1317.  
  1318. format_info (arg, from_tty)
  1319.      char *arg;
  1320.      int from_tty;
  1321. {
  1322.   if (arg)
  1323.     error ("\"info format\" does not take any arguments.");
  1324.   printf ("Prettyprinting of structures is %s.\n",
  1325.       prettyprint ? "on" : "off");
  1326.   printf ("Printing of unions interior to structures is %s.\n",
  1327.       unionprint ? "on" : "off");
  1328.   if (print_max == UINT_MAX)
  1329.     printf_filtered
  1330.       ("There is no maximum number of array elements printed.\n");
  1331.   else
  1332.     printf_filtered
  1333.       ("The maximum number of array elements printed is %d.\n", print_max);
  1334. }
  1335.  
  1336. extern struct cmd_list_element *setlist;
  1337.  
  1338. void
  1339. _initialize_valprint ()
  1340. {
  1341.   add_cmd ("array-max", class_vars, set_maximum_command,
  1342.        "Set NUMBER as limit on string chars or array elements to print.\n\
  1343. \"set array-max 0\" causes there to be no limit.",
  1344.        &setlist);
  1345.  
  1346.   add_cmd ("prettyprint", class_support, set_prettyprint_command,
  1347.        "Turn prettyprinting of structures on and off.",
  1348.        &setlist);
  1349.   add_alias_cmd ("pp", "prettyprint", class_support, 1, &setlist);
  1350.  
  1351.   add_cmd ("unionprint", class_support, set_unionprint_command,
  1352.        "Turn printing of unions interior to structures on and off.",
  1353.        &setlist);
  1354.  
  1355.   add_info ("format", format_info,
  1356.         "Show current settings of data formatting options.");
  1357.  
  1358.   /* Give people the defaults which they are used to.  */
  1359.   prettyprint = 0;
  1360.   unionprint = 1;
  1361.  
  1362.   print_max = 200;
  1363.  
  1364.   unsigned_type_table
  1365.     = (char **) xmalloc ((1 + sizeof (unsigned LONGEST)) * sizeof (char *));
  1366.   bzero (unsigned_type_table, (1 + sizeof (unsigned LONGEST)));
  1367.   unsigned_type_table[sizeof (unsigned char)] = "unsigned char";
  1368.   unsigned_type_table[sizeof (unsigned short)] = "unsigned short";
  1369.   unsigned_type_table[sizeof (unsigned long)] = "unsigned long";
  1370.   unsigned_type_table[sizeof (unsigned int)] = "unsigned int";
  1371. #ifdef LONG_LONG
  1372.   unsigned_type_table[sizeof (unsigned long long)] = "unsigned long long";
  1373. #endif
  1374.  
  1375.   signed_type_table
  1376.     = (char **) xmalloc ((1 + sizeof (LONGEST)) * sizeof (char *));
  1377.   bzero (signed_type_table, (1 + sizeof (LONGEST)));
  1378.   signed_type_table[sizeof (char)] = "char";
  1379.   signed_type_table[sizeof (short)] = "short";
  1380.   signed_type_table[sizeof (long)] = "long";
  1381.   signed_type_table[sizeof (int)] = "int";
  1382. #ifdef LONG_LONG
  1383.   signed_type_table[sizeof (long long)] = "long long";
  1384. #endif
  1385.  
  1386.   float_type_table
  1387.     = (char **) xmalloc ((1 + sizeof (double)) * sizeof (char *));
  1388.   bzero (float_type_table, (1 + sizeof (double)));
  1389.   float_type_table[sizeof (float)] = "float";
  1390.   float_type_table[sizeof (double)] = "double";
  1391. }
  1392.  
  1393.